﻿using ObjectBakery;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace ObjectBakery.Tests
{
    
    
    /// <summary>
    ///This is a test class for ProxyTest and is intended
    ///to contain all ProxyTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectProxyTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion




        /// <summary>
        ///A test for InvokeMethod
        ///</summary>
        [TestMethod()]
        public void InvokeMethodTest()
        {
            //string strTypeName = string.Empty; // TODO: Initialize to an appropriate value
            //string strSource = string.Empty; // TODO: Initialize to an appropriate value
            //Language language = new Language(); // TODO: Initialize to an appropriate value
            //ObjectProxy target = new ObjectProxy(strTypeName, strSource, language); // TODO: Initialize to an appropriate value
           
            //string strMethod = string.Empty; // TODO: Initialize to an appropriate value
            //object expected = null; // TODO: Initialize to an appropriate value
            //object actual;
            //actual = target.InvokeMethod(strSource, strMethod);
            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }






        string strTypeName = "ObjectBakery.Tests.TestDoubles.Asset";
        string strSource = File.ReadAllText(@".\Asset.cs");
        Language language = Language.CSharp;


        /// <summary>
        ///A test for Proxy Constructor
        ///</summary>
        [TestMethod()]
        public void ProxyConstructorTest()
        {

            ScriptProxy target = new ScriptProxy(strTypeName, strSource, language);

            Assert.AreEqual(strTypeName, target.ProxiedObject.GetType().ToString());

        }



        //TODO: Bring method and datasetting automation into Proxy
        [TestMethod]
        public void CanProxyScriptAutomation()
        {
            ScriptProxy target = new ScriptProxy(strTypeName, strSource, language);

           object ret = target.InvokeMethod("ToString", new object[]{});

           Assert.AreEqual(strTypeName, ret.ToString());

        }

        [TestMethod]
        public void CanProxyScriptAutomationPassingAndReturningParameters()
        {
            ScriptProxy target = new ScriptProxy(strTypeName, strSource, language);

            string text = "Hello Reflection";

            object ret = target.InvokeMethod("Repeat", new object[] { text });

            Assert.AreEqual(text, ret.ToString());

        }





      
    }
}
